package com.example.backend.rest;

import com.example.backend.mapper.ManufacturerMapper;
import com.example.backend.model.Manufacturer;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/manu")
public class ManuFacturerRest {

    @Autowired
    SqlSessionFactory factory;

    @GetMapping("all")
    public List<Manufacturer> allManus(){
        SqlSession sess = factory.openSession();
        ManufacturerMapper mapper = sess.getMapper(ManufacturerMapper.class);
        List<Manufacturer> manus = mapper.allManus();
        sess.close();
        return manus;
    }
}
